﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Ord.Api.Migrations
{
    public partial class init : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("MySql:CharSet", "utf8mb4 ");

            migrationBuilder.CreateTable(
                name: "event_tracker",
                columns: table => new
                {
                    id = table.Column<long>(type: "bigint", nullable: false, comment: "")
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    event_id = table.Column<string>(type: "longtext", nullable: false, comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4 "),
                    tracker_name = table.Column<string>(type: "longtext", nullable: false, comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4 "),
                    modify_by = table.Column<long>(type: "bigint", nullable: true, comment: ""),
                    modify_time = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: ""),
                    create_by = table.Column<long>(type: "bigint", nullable: false, comment: ""),
                    create_time = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "")
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_event_tracker", x => x.id);
                },
                comment: "")
                .Annotation("MySql:CharSet", "utf8mb4 ");

            migrationBuilder.CreateTable(
                name: "order",
                columns: table => new
                {
                    id = table.Column<long>(type: "bigint", nullable: false, comment: ""),
                    is_deleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: ""),
                    customer_id = table.Column<long>(type: "bigint", nullable: false, comment: ""),
                    amount = table.Column<decimal>(type: "decimal(18,4)", nullable: false, comment: ""),
                    remark = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true, comment: "")
                        .Annotation("MySql:CharSet", "utf8mb4 "),
                    statuscode = table.Column<int>(type: "int", nullable: false),
                    statuschangesreason = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4 "),
                    receivername = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4 "),
                    receiverphone = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4 "),
                    receiveraddress = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4 "),
                    modify_by = table.Column<long>(type: "bigint", nullable: true, comment: ""),
                    modify_time = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: ""),
                    create_by = table.Column<long>(type: "bigint", nullable: false, comment: ""),
                    create_time = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: ""),
                    version = table.Column<DateTime>(type: "timestamp(6)", rowVersion: true, nullable: false, comment: "")
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn)
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_order", x => x.id);
                },
                comment: "")
                .Annotation("MySql:CharSet", "utf8mb4 ");

            migrationBuilder.CreateTable(
                name: "order_item",
                columns: table => new
                {
                    id = table.Column<long>(type: "bigint", nullable: false, comment: ""),
                    is_deleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: ""),
                    order_id = table.Column<long>(type: "bigint", nullable: false, comment: ""),
                    producid = table.Column<long>(type: "bigint", nullable: false),
                    productname = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4 "),
                    productprice = table.Column<decimal>(type: "decimal(18,4)", nullable: false),
                    count = table.Column<int>(type: "int", nullable: false, comment: ""),
                    version = table.Column<DateTime>(type: "timestamp(6)", rowVersion: true, nullable: false, comment: "")
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn),
                    modify_by = table.Column<long>(type: "bigint", nullable: true, comment: ""),
                    modify_time = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: ""),
                    create_by = table.Column<long>(type: "bigint", nullable: false, comment: ""),
                    create_time = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "")
                },
                constraints: table =>
                {
                    table.PrimaryKey("pk_order_item", x => x.id);
                    table.ForeignKey(
                        name: "fk_order_item_order_order_id",
                        column: x => x.order_id,
                        principalTable: "order",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "")
                .Annotation("MySql:CharSet", "utf8mb4 ");

            migrationBuilder.CreateIndex(
                name: "ix_order_item_order_id",
                table: "order_item",
                column: "order_id");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "event_tracker");

            migrationBuilder.DropTable(
                name: "order_item");

            migrationBuilder.DropTable(
                name: "order");
        }
    }
}
